package util;

import java.util.Arrays;
import java.util.Random;

/**
 * 生成随机数的工具类
 */
public class GetRandom {
    public static int[] rdArr(){
        Random rd = new Random();
        // 随机生成5道题,含每道题的答案
        int[] arr = new int[5];
        int num;
        int i = 0;
        outer: while (i < arr.length) {
            num = rd.nextInt(9) ;
            for (int j = 0; j < arr.length; j++) {
                if (arr[j] == num) {
                    continue outer;
                }
            }
            arr[i] = num;
            i++;
        }
        System.out.println(Arrays.toString(arr));
        return arr;
    }

    public static void main(String[] args) {
        GetRandom.rdArr();
    }

}
